#include <unistd.h>
#include <cstdlib>
#include <ctime>
#include "ThreadPool.hpp"
#include "Task.hpp"


// 用户层定义

using namespace myThreadPool;
using namespace myLog;

/* int main(){
    
    srand((unsigned int)time(nullptr));// 设置时间戳，后序随机获取任务
    int taski = 0;

    //ThreadPool<int> threadpool;
    ThreadPool<task_t> threadpool;

    threadpool.Start();
    // 这里要睡一下，要不然有些线程可能名字还没有换过来！
    sleep(1);

    int cnt = 20;
    while(cnt--){
        taski = rand() % 5; //0 ~ 4 
        threadpool.Enqueue(_tasks[taski]);
    }

    sleep(3);
    threadpool.Stop();

    threadpool.Join();
    LOG(LogLevel::INFO) << "主线程退出" ;
    return 0;
} */





int main(){
    
    srand((unsigned int)time(nullptr));// 设置时间戳，后序随机获取任务
    int taski = 0;

    // 第一次获取单例 -> 获取到并启动线程池
    //ThreadPool<task_t>::GetInstance();

    int cnt = 30;
    while(cnt--){
        taski = rand() % 5; //0 ~ 4 
        ThreadPool<task_t>::GetInstance()->Enqueue(_tasks[taski]);
    }

    sleep(3);
    ThreadPool<task_t>::GetInstance()->Stop();

    ThreadPool<task_t>::GetInstance()->Join();
    LOG(LogLevel::INFO) << "主线程退出" ;

    return 0;
}